//
//  SCJumpViewController.m
//  shareDemo
//
//  Created by 翟少聪 on 16/9/29.
//  Copyright © 2016年 Nice. All rights reserved.
//

#import "SCJumpViewController.h"
#import "SCPageViewHeader.h"
#import "SCDemoViewController.h"
#import "AdvertModel.h"

#define HEIGHT_NAVBAR    ([[UIScreen mainScreen ] bounds ].size.height == 812.0 ? 88 : 64)


@interface SCJumpViewController ()

@property (nonatomic, strong) SCPageView *pageView;
@property (nonatomic, strong) NSDictionary *dic;

@end

@implementation SCJumpViewController
{
    RequestServices *service;
    NSMutableArray *imgArr;
}
- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    [self.titleView setHidden:YES];
    [self.backKuang setHidden:YES];
    [self.backImgView setHidden:YES];
}

//广告页
- (void)viewDidLoad {
    [super viewDidLoad];
    imgArr = [NSMutableArray array];
    /*
     * 轮播图接口
     */
    service = [[RequestServices alloc]initWithDelegate:self];
    [service getAdvert:@"1" tag:8000];
}

-(void)getFinished:(NSDictionary *)obj tag:(long long)tag{
    if (tag == 8000){
        NSArray *urlArr = [AdvertModel mj_objectArrayWithKeyValuesArray:obj[@"list"]];
        for (int i = 0; i<urlArr.count; i++) {
            AdvertModel *model = urlArr[i];
            [imgArr addObject:model.advertUrl];
        }
        if (urlArr.count > 0) {
            self.dic = [urlArr[0] mj_keyValues];
        }
        [self pageViewInit];

    }
}


- (void)pageViewInit {
    WS(weakSelf);
    SCCountdownLabel *countdownLabel = [[SCCountdownLabel alloc] initWithFrame:CGRectMake(KScreenWidth - 80, HEIGHT_NAVBAR - 44, 60, 30)];
    countdownLabel.blockNewViewController = ^{
        [weakSelf removerSCPageView];
    };
    _pageView = [[SCPageView alloc] initWithFrame:CGRectMake(0, 0, KScreenWidth, KScreenHeight)];
    //广告图片
    _pageView.pageURLString = [NSString stringWithFormat:@"%@",self.dic[@"advertUrl"]];
    _pageView.advertisingPageImageView.image = DefaultImg;
    _pageView.blockSelect = ^{
        NSLog(@"广告页被点击。。。");
        countdownLabel.isStop = NO;
        SCDemoViewController *demoVC = [[SCDemoViewController alloc] init];
        demoVC.titleStr = [NSString stringWithFormat:@"%@",weakSelf.dic[@"advertName"]];
        demoVC.url = [NSString stringWithFormat:@"%@",weakSelf.dic[@"jumpContent"]];
        [weakSelf PushToViewController:demoVC];
    };
    [self.view addSubview:_pageView];
    
    [_pageView addSubview:countdownLabel];
}

- (void)removerSCPageView {
    WS(weakSelf);
//    [UIView animateWithDuration:0.5 animations:^{
//        weakSelf.pageView.alpha = 0.0;
//    } completion:^(BOOL finished) {
        if (weakSelf.blockMainViewController) {
            weakSelf.blockMainViewController();
        }
//    }];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
